<tc_include file="Public:head" />
<style>
	body{background: #ebebeb}
</style>
<div class="container" id="container">
	<div class="page">
	    <div class="page__bd" style="height: 100%; overflow: hidden;">
	    	<div class="weui-tab">
	            <div class="weui-tab__panel">
	            	<div class="reg-box">
	            		<!--注册-->
		            	<div class="weui-cells weui-cells_form">
				            <div class="weui-cell">
				                <div class="weui-cell__hd">
				                    <label class="weui-label">手机号</label>
				                </div>
				                <div class="weui-cell__bd">
				                    <input class="weui-input" type="tel" id="mobile" placeholder="请输入手机号">
				                </div>
				            </div>
				            <div class="weui-cell weui-cell_vcode">
				                <div class="weui-cell__hd">
				                	<label class="weui-label">验证码</label>
				                </div>
				                <div class="weui-cell__bd">
				                    <input class="weui-input" type="number" id="yzm" placeholder="请输入获取验证码">
				                </div>
				                <div class="weui-cell__ft">
				                    <button class="weui-vcode-btn" id="sendId" onclick="sendSms()">获取验证码<span>send me security code</span></button>
				                </div>
				            </div>
				            <div class="weui-cell">
				                <div class="weui-cell__hd">
				                	<label class="weui-label">新密码</label>
				                </div>
				                <div class="weui-cell__bd">
				                    <input class="weui-input" type="password" id="password" placeholder="">
				                </div>
				                <div class="weui-cell__ft">
				                    <span>6位以上数字及密码</span>
				                </div>
				            </div>
				        </div>
				        <div class="weui-btn-area">
				            <a class="weui-btn weui-btn_default" href="javascript:" id="regBtn">提交<br /><span>submit</span></a>
				        </div>
				        
				        <!--注册 end-->
			        </div>
	            </div>
				<tc_include file="Public:menu" />
	    	</div>
	    </div>		    
	</div>
</div>

<div id="dialogs">
	<!--BEGIN regDialog-->
	<div class="js_dialog" id="errDialog" style="display: none;">
		<div class="weui-mask"></div>
		<div class="weui-dialog notice-dialog">
			<div class="weui-dialog__btn">&times;</div>
			<div class="icon-box">
				<i class="icon iconfont icon-notice"></i>
			</div>
			<div class="weui-dialog__bd">
				<div class="weui-dialog__title">验证成功！</div>
				<p>欢迎加入夏都小镇，<font>即将跳转会员页面！</font></p>
			</div>
		</div>
	</div>
	<!--END regDialog-->
</div>
<tc_include file="Public:footer" />
<script>
    function show_dialog(title, content) {
        $(".weui-dialog__bd .weui-dialog__title").html(title);
        $(".weui-dialog__bd p").html(content);
        $('#errDialog').fadeIn(0);
    }

	//关闭dialogs
	$('#dialogs').on('click', '.weui-dialog__btn', function(){
		$(this).parents('.js_dialog').fadeOut(0);
	});

    function sendSms(){
        var mobile = $('#mobile').val();
        var isMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;

        if(!isMobile.exec(mobile)){
            show_dialog('错误提示','请输入正确的手机号');
            return false;
        }

        $.post("{:U('public/sendSms')}", { mobile: mobile }, function (data) {
            if (data.code == 200) {
                setTimeout(function(){
                    time();
                    show_dialog('发送成功！','');
                }, 1000);
            }
            else {
                show_dialog('发送失败！',data.message);
            }
        });
    }

    var wait=60;
    function time() {
        var smsObj = $('#sendId');
        if (wait == 0) {
            smsObj.attr('onclick','sendSms();');
            smsObj.html("获取验证码<span>send me security code</span>");
            wait = 60;
        } else {
            smsObj.attr('onclick','void(0);');
            smsObj.html("重新发送(" + wait + ")<span>send me security code</span>");
            wait--;
            setTimeout(function() { time() },1000);
        }
    }

    $("#regBtn").click(function () {
        var mobile = $('#mobile').val();
        var password = $("#password").val();
        var yzm = $("#yzm").val();


        var isMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;

        var isPassword = /^[0-9a-zA-Z_]{6,15}$/;

        if(!isMobile.exec(mobile)){
            show_dialog('错误提示！','请输入正确的手机号');
            return false;
        }
        if(yzm == ''){
            show_dialog('错误提示！','请输入验证码');
            return false;
        }
        if(!isPassword.exec(password)){
            show_dialog('错误提示！','请输入6位以上数字及密码');
            return false;
        }

        $.post("{:U('forget/dologin')}", {mobile: mobile, password: password, yzm:yzm}, function (data) {
            if (data.code == 200) {
                show_dialog('验证成功',"");
                setTimeout(function(){
                    location.href = "{:U('public/login')}";
                }, 1000);
            }
            else {
                show_dialog('验证失败', data.message);
            }
        });

    });
</script>
